//
//  FinishedOrderHeader.m
//  RRQS
//
//  Created by kuyuZJ on 16/8/17.
//
//

#import "FinishedOrderHeader.h"

@interface FinishedOrderHeader ()

@property(nonatomic,strong) UIView* bottomView;
@property(nonatomic,strong) UILabel* labelDate;
@property(nonatomic,strong) UILabel* labelCount;

@end


@implementation FinishedOrderHeader

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.backgroundColor = [UIColor colorWithRed:231/255.f green:231/255.f blue:231/255.f alpha:1.0];
        [self layoutUI];
        [self layoutConstraints];
    }
    return self;
}


#pragma mark =====================================================  user interface layout
-(void)layoutUI{
    [self addSubview:self.bottomView];
    [self.bottomView addSubview:self.labelDate];
    [self.bottomView addSubview:self.labelCount];

}

-(void)layoutConstraints{
    NSArray* formats = @[ @"H:|-0-[bottomView]-0-|", @"V:|-10-[bottomView]-0-|",
                          @"H:|-10-[labelDate(==halfWidth)]", @"V:|-0-[labelDate]-0-|",
                          @"H:[labelCount(==halfWidth)]-10-|", @"V:|-0-[labelCount]-0-|"
                          ];
    NSDictionary* metorics = @{ @"halfWidth":@(SCREEN_WIDTH/3)};
    NSDictionary* views = @{ @"bottomView":self.bottomView, @"labelDate":self.labelDate, @"labelCount":self.labelCount};     
    for (NSString* format in formats) {
        NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:format options:0 metrics:metorics views:views];
        [self addConstraints:constraints];
    }     
}

#pragma mark =====================================================  property pacakge
-(void)setEntity:(MFinishedTask *)entity{
    if(entity){
        _entity = entity;
        self.labelDate.text = entity.date;
        self.labelCount.text =[NSString stringWithFormat:@"完成%ld单", [entity.count integerValue]];
    }
}
-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc]init];
        _bottomView.backgroundColor = [UIColor colorWithRed:254/255.f green:228/255.f blue:181/255.f alpha:1.0];
        _bottomView.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _bottomView;
}

-(UILabel *)labelDate{
    if(!_labelDate){
        _labelDate = [[UILabel alloc]init];
        _labelDate.textAlignment = NSTextAlignmentLeft;
        _labelDate.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelDate;
}

-(UILabel *)labelCount{
    if(!_labelCount){
        _labelCount = [[UILabel alloc]init];
        _labelCount.textAlignment = NSTextAlignmentRight;
        _labelCount.textColor = [UIColor colorWithRed:83/255.f green:83/255.f blue:83/255.f alpha:1.0];
        _labelCount.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelCount;
}
 
@end
